package com.mlog.njyjy.ndop.monitor.pojo;

import java.io.Serializable;
import java.util.Date;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class ResponseMessage implements Serializable{

    private static final long serialVersionUID = 1L;
    private int code;
    private String message;
    private Object data;
    private long timestamp;
    
    private ResponseMessage(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.timestamp = new Date().getTime();
    }
    
    public static ResponseMessage success() {
        return getResponseMessage(ResponseStatus.SUCCEED, "");
    }
    
    public static ResponseMessage success(Object data) {
        return getResponseMessage(ResponseStatus.SUCCEED, data);
    }
    
    public static ResponseMessage error(ResponseStatus t) {
        return getResponseMessage(t, null);
    }
    
    public static ResponseMessage error(Exception e) {
        return new ResponseMessage(500, e.getMessage(), null);
    }
    
    public static ResponseMessage error() {
        return getResponseMessage(ResponseStatus.FAILED, null);
    }
    
    public static ResponseMessage getResponseMessage(ResponseStatus t, Object data) {
        return new ResponseMessage(t.getCode(), t.getMessage(), data);
    }


}
